/* eslint-disable */

//第三方类库加载管理js，方便切换lib


var configLibs = {

  ////////////////////////// UI界面相关库////////////////////////
  'jquery': [
    "jquery/jquery-2.1.4.min.js",
  ],

  ////////////////////////// 其他库////////////////////////
  'haoutil': [
    "hao/haoutil.js"
  ]
}


//内部处理方法
; (function () {
  var r = new RegExp('(^|(.*?\\/))(include-lib.js)(\\?|$)'),
    s = document.getElementsByTagName('script'),
    targetScript
  for (var i = 0; i < s.length; i++) {
    var src = s[i].getAttribute('src')
    if (src) {
      var m = src.match(r)
      if (m) {
        targetScript = s[i]
        break
      }
    }
  }

  // cssExpr 用于判断资源是否是css
  var cssExpr = new RegExp('\\.css')

  function inputLibs (list, baseUrl) {
    if (list == null || list.length === 0) {
      return
    }

    for (var i = 0, len = list.length; i < len; i++) {
      var url = list[i]
      if (!url.startsWith("http") && !url.startsWith("//:")) {
        url = baseUrl + url
      }

      if (cssExpr.test(url)) {
        var css = '<link rel="stylesheet" href="' + url + '">'
        document.writeln(css)
      } else {
        var script = '<script type="text/javascript" src="' + url + '"><' + '/script>'
        document.writeln(script)
      }
    }
  }

  //加载类库资源文件
  function load () {
    var arrInclude = (targetScript.getAttribute('include') || '').split(',')
    var libpath = targetScript.getAttribute('libpath') || ''
    if (libpath.lastIndexOf('/') !== libpath.length - 1) {
      libpath += '/'
    }


    var keys = {}
    for (var i = 0, len = arrInclude.length; i < len; i++) {
      var key = arrInclude[i]

      if (keys[key]) {
        //规避重复引入lib
        continue
      }
      keys[key] = true

      inputLibs(configLibs[key], libpath)
    }
  }

  load()
})()
